﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DynamicViewFormApp.Handler
{
    class PageHander
    {
        private static bool MoveFlag;//移动标记
        private static int xPos;//X坐标
        private static int yPos;//Y坐标

        /// <summary>
        /// 控件鼠标松开
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        internal static void Component_MouseUp(object sender, MouseEventArgs e)
        {
            MoveFlag = false;
        }
        /// <summary>
        /// 控件鼠标按下
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        internal static void Component_MouseDown(object sender, MouseEventArgs e)
        {
            //获取当前控件
            Control control = sender as Control;
            MoveFlag = true;
            xPos = e.X;
            yPos = e.Y;
        }
        /// <summary>
        /// 控件鼠标移动
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        internal static void Component_MouseMove(object sender, MouseEventArgs e)
        {
            //获取当前控件
            Control control = sender as Control;

            if (MoveFlag && (Control.ModifierKeys & Keys.Control) == Keys.Control)
            {
                control.Left += Convert.ToInt16(e.X - xPos);
                control.Top += Convert.ToInt16(e.Y - yPos);
            }
        }
        private void RichTextBox_ContentsResized(object sender, ContentsResizedEventArgs e)
        {
            RichTextBox rtb = sender as RichTextBox;
            rtb.Height = e.NewRectangle.Height + 10;
            //DrawDashRectangle(rtb, panel1);
        }
    }
}
